import { useUserStore } from '@/store';

/**
 * 动作权限
 */
export const usePermission = () => {
  const userStore = useUserStore();

  /**
   * 判断是否有操作权限
   * @param action 动作符号,默认为：实体类.操作，如：User.save
   */
  const hasPermission = (action: string) => {
    return action && userStore.actions.includes(action);
  };

  /**
   * 判断是否有工作组操作权限
   * @param action 动作符号,默认为：实体类.操作，如：User.save
   */
  const hasWgPermission = (action: string) => {
    return action && userStore.wgActions.includes(action);
  };

  return {
    hasPermission,
    hasWgPermission,
  };
};